#ifndef __CINT__
#include <TSystem.h>
#include <TFile.h>
#include <TLegend.h>
#include <TGraph.h>
#include <SIM/CpParticle.h>
#include <TCanvas.h>
#include <TAxis.h>
#include <TStyle.h>
#endif
void ShowHist()
{
  gStyle = new TStyle("Plain","Plain");
  gStyle->UseCurrentStyle();
  
  gSystem->Load("libCPBase.so");
  gSystem->Load("libCPPhysics.so");
  gSystem->Load("libCPSim.so");


  TCanvas *c43 = new TCanvas("c","Radius nano particle",200,10,600,400);
  
  TString fname="/home/mvala/projects/coldpig/build/coldpig/CpSim.root";
    
  TFile *f = TFile::Open(fname.Data(), "READ");
  TTree *tree = (TTree*) f->Get("cpSimTree");
  CpParticle *part = 0;
  //   tree->Print();
  tree->SetBranchAddress("cpParticles", &part);
  
  Long64_t numEvents = tree->GetEntries();

  TString legStrings[] = { "100 nm","300 nm","500 nm","700 nm" };

  TLegend *legend = new TLegend(0.6,0.3,0.8,0.5);
  legend->SetHeader("Radius R_{p}");

//   numEvents = 1;
  TString opts="AL";
  CpTrack *track;
  for(Long64_t iEvent=0;iEvent<numEvents;iEvent++) {
    tree->GetEntry(iEvent);
    TGraph *gr = new TGraph();
//     part->Print();
    for ( Long64_t iParticle=0; iParticle<part->GetNumberOfTracks();iParticle++ ) {
      track = (CpTrack*) part->GetTrack(iParticle);
      for (Long64_t iPoint=0; iPoint<track->GetNumberOfPoints();iPoint++){
        CpPoint *p = (CpPoint*) track->GetPoint(iPoint);
//         p->Print();
        gr->SetPoint(iPoint,p->GetZ(),p->GetY());
        
      }
    }
    Printf("%d %p",iEvent,gr);

    gr->SetNameTitle(Form("gr%d",iEvent),legStrings[iEvent]);
    gr->GetXaxis()->SetRangeUser(0.07,0.1);
    gr->GetXaxis()->SetTitle("z [m]");
    gr->GetYaxis()->SetTitle("y [m]");
    gr->SetMarkerStyle(20);
    gr->SetLineStyle(kDot+iEvent);
    gr->SetLineWidth(3);
    gr->Draw(opts.Data());
    legend->AddEntry(Form("gr%d",iEvent),gr->GetTitle(),"l");
    gr->SetTitle("");
    
    opts ="CL";
  }

  legend->Draw();
    
}
